<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>美兰数据文化馆与图书馆</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/css/public.css" media="all">
    <link rel="shortcut icon" href="<%=request.getContextPath()%>/huazhi/images/favicon.ico"/>
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/dtree/dtree.css" media="all">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/dtree/font/dtreefont.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-xs3">
            <div class="layui-card">
                <div class="layui-card-body">
                    <ul id="demoTree1" class="dtree" data-id="0"></ul>
                </div>
            </div>
        </div>
        <div class="layui-col-xs9">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-tab-content">
                        <table id="data" lay-filter="datas"></table>
                        <div id="laypage"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<input type="hidden" id="id">
<script type="text/html" id="dataDemo">
    <shiro:hasPermission name="sys:dic:add">
        <div class="layui-inline" lay-event="add" title="添加">
            <i class="layui-icon layui-icon-add-1"></i>
        </div>
    </shiro:hasPermission>
</script>
<input type="hidden" id="curnum" value="1">
<script src="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/layui.all.js"></script>
<script src="<%=request.getContextPath()%>/huazhi/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['datadictionary', 'table', 'dtree'], function () {
        var $ = layui.$
            , table = layui.table
            , layer = layui.layer
            , dtree = layui.dtree;

        dtree.render({
            elem: "#demoTree1",
            url: "<%=request.getContextPath()%>/rest/system/getTreeStructure",
            dataFormat: "list",  //配置data的风格为list
            dataStyle: "layuiStyle",  //使用layui风格的数据格式
            response: {message: "msg", statusCode: 0},  //修改response中返回数据的定义
            skin: "laySimple", // laySimple主题风格
            line: true,  // 显示树线
            height: "full",
            icon: "-1",  // 隐藏二级图标, // 隐藏一级图标
            width: "80%",
            // initLevel: 3,
        });


        // 点击节点触发回调
        dtree.on("node('demoTree1')", function (obj) {
//            layer.msg(JSON.stringify(obj.param));
            var nodeId = JSON.stringify(obj.param.nodeId)
            var context = JSON.stringify(obj.param.context)
            nodeId = nodeId.replace(/\"/g, "");
            $("#id").val(nodeId);
            $("#curnum").val("1");
            table.reload('data', { //表格的id
                where: {
                    key: "",
                    page: 1,
                    limit: 10,
                    id: nodeId
                },
                text: {
                    none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                }
            })

        });


        //监听基本信息表格上面的工具蓝
        table.on('toolbar(datas)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id)
                , data = checkStatus.data; //获取选中的数据
            switch (obj.event) {
                case 'add':
                    var id = $("#id").val();
                    if (id == "1" || id == "") {
                        layer.msg("请选择属性")
                    } else {
                        add(id);
                    }
                    break;
            }
        });

        function add(id) {
            var clocess = "1";
            var index = layer.open({
                title: "添加",
                type: 2,
                content: '<%=request.getContextPath()%>/rest/getRoute?type=system&url=datadictionary_add',
                area: ['90%', '91%'],
                maxmin: true,
                //是否显示右上角关闭图标，默认为1，显示
                anim: 4,
                shade: 0.6,
                skin: 'layui-layer-molv',
                resize: true,
                success: function (layero, index) {  //当你需要在层创建完毕时即执行一些语句，可以通过该回调 想相当于吧值转到子界面
                    // var body = layer.getChildFrame('body',index);//建立父子联系  //当你试图在当前页获取iframe页的DOM元素时，你可以用此方法。
                    // body.find("#id").val(id);
                    var iframe = window['layui-layer-iframe' + index];
                    //调用子页面的全局函数
                    iframe.child(id)
                },
                cancel: function (index, layero) {
                    layer.close(index)
                    clocess = "2"
                    return false;
                },
                end: function () {
                    if (clocess == "2") {

                    } else {
                        table.reload('data', { //表格的id
                            where: {
                                id: id,
                            },
                            text: {
                                none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                            }
                        })
                    }
                    return false;
                }
            });
            // $('.layui-layer-setwin .layui-layer-max').css("display", "none")
            // $('.layui-layer-setwin .layui-layer-min').css("display", "none")
//            setTimeout(function(){
//                layui.layer.tips('点击此处返回数据库字典列表', '.layui-layer-setwin .layui-layer-close', {
//                    tips: 3
//                });
//            },500)
//            layer.full(index);
//            window.sessionStorage.setItem("index",index);
//            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
//            $(window).on("resize",function(){
//                layer.full(window.sessionStorage.getItem("index"));
//            })
        }

    });
</script>
</body>
</html>
